package com.hnkj.caiyunweather.logic.dao

import android.content.Context
import com.google.gson.Gson
import com.hnkj.caiyunweather.WeathrerApplication
import com.hnkj.caiyunweather.logic.model.Place

object PlaceDao {
    fun savePlace(place: Place){
        sharedPreferences().edit().putString("place",Gson().toJson(place)).apply()
    }
    fun getSavePlace():Place{
        val placeJson = sharedPreferences().getString("place","")
        return Gson().fromJson(placeJson,Place::class.java)
    }

    fun isPlaceSaved() = sharedPreferences().contains("place")

    private fun sharedPreferences() = WeathrerApplication.context.getSharedPreferences("caiyun_weather",
        Context.MODE_PRIVATE)

}